package com.balabala.gym_goods.controller.app;

import com.balabala.api.ShippingAddressFeignClient;
import com.balabala.gym_goods.pojo.dto.AppFindByNameDto;
import com.balabala.gym_goods.pojo.entity.Category;
import com.balabala.gym_goods.pojo.entity.Course;
import com.balabala.gym_goods.pojo.entity.Spu;
import com.balabala.gym_goods.service.CategoryService;
import com.balabala.gym_goods.service.SpuService;
import com.balabala.result.Result;
import com.balabala.vo.ShippingAddressVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:zl
 * Date:2023/5/7 15:18
 */
@Slf4j
@RestController
@Api(tags = "小程序商城接口")
@CrossOrigin
@RequestMapping("/app/shopping")
public class ShoppingController {


    @Autowired
    private SpuService spuService;
    @Autowired
    private ShippingAddressFeignClient shippingAddressFeignClient;

    @ApiOperation(value = "查询所有商品")
    @PostMapping(value = "/findAllGoods")
    public Result findAllGoods() {
        List<Spu> list = spuService.list();
        return Result.ok(list);
    }

    @ApiOperation(value = "根据商品名字模糊搜索商品")
    @PostMapping(value = "/findByName")
    public Result findByName(@RequestBody AppFindByNameDto appFindByNameDto) {
        List<Spu> list = spuService.findByName(appFindByNameDto);
        return Result.ok(list);
    }

    @ApiOperation(value = "根据商品id查询商品详情")
    @PostMapping(value = "/findByShoppingId{id}")
    public Result findByShoppingId(@PathVariable("id") Long id) {
        Spu byId = spuService.getById(id);
        return Result.ok(byId);
    }

    @ApiOperation(value = "根据用户id查询收货地址")
    @GetMapping(value = "/findById")
    public Result findById(@RequestParam Long userId) {
        Result<List<ShippingAddressVo>> userAllShippingAddress = shippingAddressFeignClient.findUserAllShippingAddress(userId);
        return Result.ok(userAllShippingAddress.getData());
    }

}
